package org.jebert.javamessage.view;

import com.google.api.translate.Language;
import com.google.api.translate.Translate;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultComboBoxModel;
import org.jebert.javamessage.control.Translator;

public class JavaMessage extends javax.swing.JFrame {

    private Translator trans = new Translator(Language.SPANISH);
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    int englis = 0;
    /** Creates new form JavaMessage */
    public JavaMessage() {
        initComponents();
        jCLanguages.setModel(dcbm);
        trans.loadLanguages(dcbm);
        dcbm.setSelectedItem(Language.ENGLISH.name()); 

    }

    private void setItens() {
            jBAcept.setText(trans.translateIt("Accept!"));
            jLLang.setText(trans.translateIt("Language:"));
            jLName.setText(trans.translateIt("Name:"));
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCLanguages = new javax.swing.JComboBox();
        jTName = new javax.swing.JTextField();
        jLLang = new javax.swing.JLabel();
        jLName = new javax.swing.JLabel();
        jBAcept = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Java Message");

        jCLanguages.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCLanguagesItemStateChanged(evt);
            }
        });
        jCLanguages.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCLanguagesActionPerformed(evt);
            }
        });

        jLLang.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLLang.setText("Language:");

        jLName.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLName.setText("Name:");

        jBAcept.setText("Acept!");
        jBAcept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAceptActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLName)
                            .addComponent(jLLang))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                            .addComponent(jCLanguages, javax.swing.GroupLayout.Alignment.LEADING, 0, 143, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(jBAcept, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCLanguages, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLLang))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(jBAcept)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCLanguagesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCLanguagesItemStateChanged
        String lang = dcbm.getSelectedItem().toString();
        trans.setLanguage(Language.valueOf(lang));
        setItens(); 
    }//GEN-LAST:event_jCLanguagesItemStateChanged

    private void jCLanguagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCLanguagesActionPerformed
    }//GEN-LAST:event_jCLanguagesActionPerformed

    private void jBAceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAceptActionPerformed
        ContactList cl = new ContactList(trans, jTName.getText());
        cl.setVisible(true);// TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jBAceptActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new JavaMessage().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAcept;
    private javax.swing.JComboBox jCLanguages;
    private javax.swing.JLabel jLLang;
    private javax.swing.JLabel jLName;
    private javax.swing.JTextField jTName;
    // End of variables declaration//GEN-END:variables
}
